package cn.liuhuan1.blogsModel.controller;


import cn.liuhuan1.entity.PageResult;
import cn.liuhuan1.entity.ReturnResult;
import cn.liuhuan1.webModelBean.api.ArticleImp;
import cn.liuhuan1.webModelBean.bo.ArticleBo;
import cn.liuhuan1.webModelBean.bo.WebListBo;
import cn.liuhuan1.webModelBean.vo.ArticleVo;
import cn.liuhuan1.webModelBean.vo.WebListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleImp articleImp;

    @RequestMapping(value = "/getArticle",method = RequestMethod.GET)
    @ResponseBody
    public ReturnResult getArticle(){
        List<ArticleVo> getArticle = articleImp.getArticle();
        return ReturnResult.succes(getArticle);
    }

    @RequestMapping(value = "/getPageArticle",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult getPageArticle(@RequestBody ArticleBo articleBo){
        PageResult<ArticleVo> pageResult =  articleImp.getPageArticle(articleBo);
        return ReturnResult.succes(pageResult);
    }

    @RequestMapping(value = "/getArticleById",method = RequestMethod.GET)
    @ResponseBody
    public ReturnResult getArticleById(@RequestParam("id") String id){
        ArticleVo articleVo = articleImp.getArticleById(id);
        return ReturnResult.succes(articleVo);
    }

    @RequestMapping(value = "/saveArticle",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult saveArticle(@RequestBody ArticleBo articleBo){
        articleImp.saveArticle(articleBo);
        return ReturnResult.succes();
    }

    @RequestMapping(value = "/updateArticle", method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult updateArticle(@RequestBody ArticleBo articleBo){
        articleImp.updateArticle(articleBo);
        return ReturnResult.succes();
    }

    @RequestMapping(value = "/delArticle",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult delArticle(@RequestParam("id") String id){
        articleImp.delArticle(id);
        return ReturnResult.succes();
    }

    @RequestMapping(value = "/updateStatus",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult updateStatus(@RequestParam("status") String status,
                                     @RequestParam("id") String id){
        articleImp.updateStatus(status,id);
        return ReturnResult.succes();
    }

    @RequestMapping(value = "/updateViewSumber",method = RequestMethod.GET)
    @ResponseBody
    public ReturnResult updateViewSumber(@RequestParam("id") String id){
        return articleImp.updateViewSumber(id);
    }

    @RequestMapping(value = "/updateReplyNumber",method = RequestMethod.GET)
    @ResponseBody
    public ReturnResult updateReplyNumber(@RequestParam("id") String id){
        return articleImp.updateReplyNumber(id);
    }

    @RequestMapping(value = "/updatePraiseSumber",method = RequestMethod.GET)
    @ResponseBody
    public ReturnResult updatePraiseSumber(@RequestParam("id") String id){
        return articleImp.updatePraiseSumber(id);
    }

}
